package com.tesis_2.Utils;

import com.example.tesis_2.R;
import com.tesis_2.BL.BLPlatos;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.MO.MOPlato;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class UTPlatosCategoryAdapter extends BaseAdapter {
	
	Context context;
	
	
	public UTPlatosCategoryAdapter(Context context) {
		this.context = context;
		
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return BLPlatos.getLsPlatos().size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return BLPlatos.getLsPlatos().get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return BLPlatos.getLsPlatos().get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			
	 		View view;
	 
			if (convertView == null) {
				
				view = new View(context);
				
				
				
			} else {
				
				view = (View) convertView;
			}
			
			MOPlato objPlato =  (MOPlato)getItem(position);
			
			view = inflater.inflate(R.layout.activity_platos_category_item, null);
			
			((TextView) view.findViewById(R.id.txvNombre_plato_category_item)).setText(objPlato.getName());
			((TextView) view.findViewById(R.id.txvNombreRest_plato_category_item)).
			setText(BLRestaurants.getRestById(objPlato.getRestaurant_id()).getName());
			((TextView) view.findViewById(R.id.txvPrecio_plato_category_item)).setText(objPlato.getCost().toString());
			((TextView) view.findViewById(R.id.txvDescr_plato_category_item)).setText(objPlato.getDescr());
			((RatingBar) view.findViewById(R.id.rbCalificacion_plato_category_item)).setRating(objPlato.getRate());
	 
			return view;
	}

}
